package com.eflow.model.flowable.converter;

import com.eflow.model.domain.EflowUser;
import com.eflow.model.flowable.model.UserElement;
import com.eflow.model.flowable.model.e.UserTypeEnum;
import com.eflow.model.utils.SpringUtils;
import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hui se
 * @description
 * @create 2021-03-05 18:16
 **/
@Configuration
public class UserTaskConverter {
    private static Map<UserTypeEnum, BaseUserListConverter> convertersMap = new HashMap<>();

    public static void addConverter(BaseUserListConverter converter) {
        addConverter(converter, converter.getUserType());
    }

    public static void addConverter(BaseUserListConverter converter, UserTypeEnum userTypeEnum) {
        convertersMap.put(userTypeEnum, converter);
    }
    public static List<EflowUser> parseUserList(UserElement userElement, String loginUser, ProcessDefinition processDefinition, String processInstanceId, String activityId, Map<String,Object> var){
        BaseUserListConverter converter = convertersMap.get(userElement.getType());
        if(converter!=null){
            return  converter.porxyList(userElement,loginUser,processDefinition,processInstanceId,activityId,var);
        }
        return Collections.emptyList();
    }

}
